/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/18 22:21
  *
  * @file       pd_adc_reg.h
  * @brief      Header file of ADC Regular group peripheral driver.
  *
  * @note       This file contains the ADC Regular group object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/18     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_ADC_REG_H
#define JLC_SKY_ADC_REG_H

#include "pd_adc.h"
#include "drivers.h"

typedef struct ADCRegularDef ADCRegular;

struct ADCRegularDef {
    ADCBase *adcBase;

    uint32_t TriggerSource;     // ADC trigger source: TIM, EXT, Software
    uint32_t SequencerLength;   // Discontinuous Mode(ADC_SQR1_L, Bits 23:20 L[3:0])
    uint32_t SequencerDiscont;  // Discontinuous Mode(ADC_CR1_DISCEN | ADC_CR1_DISCNUM)
    uint32_t ContinuousMode;    // ADC Mode: single or continuous
    uint32_t DMATransfer;       // ADC DMA transfer


    void (*init)(ADCRegular *this);

    void (*start)(ADCRegular *this);

    /**
     * @brief The regular group share a 16 bit Regular Data Register(ADC_DR).
     *
     * @param this          ADC Regular instance
     * @param Rank          ADC Sequencer
     * @param Channel       ADC channel
     * @param SamplingTime  ADC sample time
     */
    uint16_t (*getValue)(ADCRegular *this, uint32_t Rank, uint32_t Channel, uint32_t SamplingTime);
};

extern const struct ADCRegularClass {
    /**
     *
     * @param adcBase           ADC Instance package
     * @param TriggerSource     ADC trigger source: TIM, EXT, Software
     * @param ContinuousMode    ADC Mode: single or continuous
     * @param DMATransfer       ADC DMA transfer
     * @return
     */
    ADCRegular *(*build)(ADCBase *adcBase,
                             uint32_t TriggerSource,
                             uint32_t SequencerLength,
                             uint32_t ContinuousMode,
                             uint32_t DMATransfer);
} ADCRegularBuilder;


#endif //JLC_SKY_ADC_REG_H
